﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.BarterSystem.Barterables.Barterable
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;

#nullable disable
namespace TaleWorlds.CampaignSystem.BarterSystem.Barterables
{
  public abstract class Barterable
  {
    private int _currentAmout;
    protected MBList<Barterable> _linkedBarterables;

    protected Barterable(Hero originalOwner, PartyBase originalParty)
    {
      this.OriginalOwner = originalOwner;
      this.OriginalParty = originalParty;
      this.CurrentAmount = 1;
      this._linkedBarterables = new MBList<Barterable>();
      this.Side = Barterable.BarterSide.Left;
    }

    public abstract string StringID { get; }

    public Hero OriginalOwner { get; private set; }

    public PartyBase OriginalParty { get; private set; }

    public abstract TextObject Name { get; }

    public int GetValueForFaction(IFaction faction)
    {
      return this.GetUnitValueForFaction(faction) * this.CurrentAmount;
    }

    public virtual void CheckBarterLink(Barterable linkedBarterable)
    {
    }

    public abstract int GetUnitValueForFaction(IFaction faction);

    public virtual int MaxAmount => 1;

    public int CurrentAmount
    {
      get => this._currentAmout;
      set
      {
        this._currentAmout = value;
        if (this._currentAmout <= this.MaxAmount)
          return;
        this._currentAmout = this.MaxAmount;
      }
    }

    public bool IsOffered { get; protected set; }

    public bool IsContextDependent { get; protected set; }

    public BarterGroup Group { get; protected set; }

    public MBReadOnlyList<Barterable> LinkedBarterables
    {
      get => (MBReadOnlyList<Barterable>) this._linkedBarterables;
    }

    public Barterable.BarterSide Side { get; }

    public void SetIsOffered(bool value)
    {
      if (this.IsOffered == value)
        return;
      this.IsOffered = value;
      foreach (Barterable linkedBarterable in (List<Barterable>) this._linkedBarterables)
        linkedBarterable.IsOffered = value;
    }

    public void AddBarterLink(Barterable barterable) => this._linkedBarterables.Add(barterable);

    public void Initialize(BarterGroup barterGroup, bool isContextDependent)
    {
      this.Group = barterGroup;
      this.IsContextDependent = isContextDependent;
    }

    public virtual bool IsCompatible(Barterable barterable) => true;

    public abstract ImageIdentifier GetVisualIdentifier();

    public virtual string GetEncyclopediaLink() => "";

    public abstract void Apply();

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
    }

    public enum BarterSide
    {
      Left,
      Right,
    }
  }
}
